﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace 一
{
    public class Student
    {
        public string StudentId { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public string Class { get; set; }

        public Student(string studentId, string name, int age, string className)
        {
            StudentId = studentId;
            Name = name;
            Age = age;
            Class = className;
        }

        public override string ToString()
        {
            return $"学号：{StudentId}，姓名：{Name}，年龄：{Age}，班级：{Class}";
        }
    }

    public class StudentManager
    {
        private List<Student> students = new List<Student>();

        public void AddStudent(Student student)
        {
            if (students.Any(s => s.StudentId == student.StudentId))
            {
                Console.WriteLine("错误：学号已存在！");
                return;
            }
            students.Add(student);
            Console.WriteLine("添加成功！");
        }

    
        public void UpdateStudent(string studentId, Student newStudent)
        {
            Student student = students.FirstOrDefault(s => s.StudentId == studentId);
            if (student == null)
            {
                Console.WriteLine("错误：学生不存在！");
                return;
            }

            student.Name = newStudent.Name;
            student.Age = newStudent.Age;
            student.Class = newStudent.Class;
            Console.WriteLine("修改成功！");
        }

      
        public void DeleteStudent(string studentId)
        {
            Student student = students.FirstOrDefault(s => s.StudentId == studentId);
            if (student == null)
            {
                Console.WriteLine("错误：学生不存在！");
                return;
            }

            students.Remove(student);
            Console.WriteLine("删除成功！");
        }

  
        public void FindStudent(string studentId)
        {
            Student student = students.FirstOrDefault(s => s.StudentId == studentId);
            if (student == null)
            {
                Console.WriteLine("未找到该学生！");
                return;
            }

            Console.WriteLine($"查询结果：{student}");
        }

     
        public void DisplayAllStudents()
        {
            if (students.Count == 0)
            {
                Console.WriteLine("暂无学生信息！");
                return;
            }

            Console.WriteLine($"\n共有 {students.Count} 名学生：");
            foreach (var student in students)
            {
                Console.WriteLine(student);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StudentManager manager = new StudentManager();

   
            Console.WriteLine("添加测试数据：");
            manager.AddStudent(new Student("001", "张三", 20, "一班"));
            manager.AddStudent(new Student("002", "李四", 19, "二班"));
            manager.AddStudent(new Student("003", "王五", 21, "一班"));
            Console.WriteLine();

            
            Console.WriteLine("当前所有学生：");
            manager.DisplayAllStudents();
            Console.WriteLine();

    
            Console.WriteLine("查询学号002：");
            manager.FindStudent("002");
            Console.WriteLine();

    
            Console.WriteLine("修改学号001的信息：");
            manager.UpdateStudent("001", new Student("001", "张三丰", 22, "三班"));
            Console.WriteLine();

        
            Console.WriteLine("删除学号003：");
            manager.DeleteStudent("003");
            Console.WriteLine();

      
            Console.WriteLine("最终学生列表：");
            manager.DisplayAllStudents();

            Console.WriteLine("\n按任意键退出...");
            Console.ReadKey();
        }
    }
}